package cn.admin.service.impl;

import cn.admin.dao.ByStagesMapper;
import cn.admin.dao.PaymentRecordMapper;
import cn.admin.dao.QuotaMapper;
import cn.admin.dao.UserMapper;
import cn.admin.entity.PaymentRecord;
import cn.admin.service.PaymentRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: 毛苏宇
 * @Description: You can do it!
 * @Date: Create in 11:23 2019/3/26
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class PaymentRecordServiceImpl implements PaymentRecordService {

    @Autowired private PaymentRecordMapper paymentRecordMapper;
    @Autowired private UserMapper userMapper;
    @Autowired private ByStagesMapper byStagesMapper;
    @Autowired private QuotaMapper quotaMapper;


    @Override
    public List<PaymentRecord> getAll() {
        return paymentRecordMapper.findAll();
    }

    @Override
    public boolean modifyStatus(int user_id, int re_id, int status) {
        double loan = byStagesMapper.findLoan(user_id);
        userMapper.updateIsPaymentStatus(status,user_id);
        byStagesMapper.updateStatus(status,user_id);
        quotaMapper.updateQuotaMoney(loan,user_id);
        return paymentRecordMapper.updateStatus(user_id, re_id, status)==1?true:false;
    }

}
